<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition template="/templatePrincipal.xhtml" xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:rich="http://richfaces.org/rich">
    <ui:define name="conteudo">
        <rich:spacer height="20"/>
        <center>
            <rich:messages layout="table"
                           errorClass="errorClass"
                           infoClass="infoClass"
                           warnClass="warnClass"
                           styleClass="painelMensagem"
                           ajaxRendered="true"/>
        </center>
        <rich:spacer height="10"/>
        <rich:simpleTogglePanel switchType="client">
            <f:facet name="header">
                #{messages.geralCriteriosPesquisa}
            </f:facet>
            <h:form id="fpAtendimentos">
                <h:panelGrid cellspacing="2" cellpadding="2" columns="4" columnClasses="field-names, fields">
                    <h:outputLabel for="itPeriodo">
                        #{messages.periodo}:
                    </h:outputLabel>
                    <a4j:outputPanel id="calendarInical" style="width:70px;">
                        <rich:calendar value="#{atendimentoPesquisarAction.paramDataInicial}"
                                       locale="BR"
                                       datePattern="dd/MM/yyyy"/>
                    </a4j:outputPanel>

                    <h:outputLabel for="itPeriodoFinal">
                        ate
                    </h:outputLabel>
                    <a4j:outputPanel id="calendarFinal" style="width:70px;">
                        <rich:calendar value="#{atendimentoPesquisarAction.paramDataInicial}"
                                       locale="BR"
                                       datePattern="dd/MM/yyyy"/>
                    </a4j:outputPanel>
                </h:panelGrid>

                <h:panelGrid cellspacing="2" cellpadding="2" columns="2" columnClasses="field-names, fields">
                    <h:outputLabel for="itUsuarioAtendimento">
                        #{messages.usuarioResponsavelAtendimento}:
                    </h:outputLabel>

                    <h:selectOneMenu id="somsuarioAtendimento" value="#{atendimentoPesquisarAction.paramUsuarioAtendimento}">
                        <s:selectItems value="#{atendimentoPesquisarAction.listaUsuarios}" var="e" label="#{e.login}" itemValue="#{e.idUsuario}" noSelectionLabel="..." />
                    </h:selectOneMenu>
                </h:panelGrid>

                <h:panelGrid cellspacing="2" cellpadding="2" columns="2" columnClasses="field-names, fields">
                    <h:outputLabel for="somAtendimentoLocal">
                        #{messages.localAtendimento}:
                    </h:outputLabel>

                    <h:selectOneMenu id="somAtendimentoLocal" value="#{atendimentoPesquisarAction.paramLocalAtendimento}">
                        <s:selectItems value="#{atendimentoPesquisarAction.listaLocais}" var="e" label="#{e.nome}" itemValue="#{e.idLocal}" noSelectionLabel="..." />
                    </h:selectOneMenu>
                </h:panelGrid>
                <h:panelGrid cellspacing="2" cellpadding="2" columns="2" columnClasses="field-names, fields">
                    <h:outputLabel for="somAtendimentoLocal">
                        #{messages.statusAtendimento}:
                    </h:outputLabel>

                    <h:selectOneRadio id="sorAcesso" styleClass="table-radio" value="#{atendimentoPesquisarAction.paramStatus}" style="vertical-align:top">
                        <f:selectItem itemValue="1" itemLabel="Aberto"/>
                        <f:selectItem itemValue="2" itemLabel="Fechado"/>
                    </h:selectOneRadio>
                </h:panelGrid>
                <br/>
                <a4j:commandLink id="clPesquisar"
                                 immediate="true"
                                 action="#{atendimentoPesquisarAction.pesquisar}"
                                 styleClass="link dr-toolbar-ext rich-toolbar"
                                 reRender="dtAtendimentos">
                    <h:graphicImage value="/resources/images/system-search.png"/>
                    <h:outputText value="#{messages.botaoPesquisar}" />
                </a4j:commandLink>
                <rich:spacer width="5"/>
                <h:commandLink id="clAbrirChamado"
                               immediate="true"
                               action="#{atendimentoCriarAction.setup}"
                               styleClass="link dr-toolbar-ext rich-toolbar">
                    <h:graphicImage value="/resources/images/list-add.png"/>
                    <h:outputText value=" #{messages.abrirChamadoAtendimento}"/>
                </h:commandLink>
            </h:form>
        </rich:simpleTogglePanel>
        <a4j:form ajaxSubmit="true">
            <rich:dataTable id="dtAtendimentos"
                            value="#{atendimentoPesquisarAction.listaAtendimentos}" var="_atendimentos"
                            width="100%" rows="10"
                            cellpadding="0" cellspacing="0"
                            captionClass="bold"
                            columnClasses="colunaCentralizada,colunaCentralizada, colunaCentralizada,colunaCentralizada,colunaCentralizada"
                            columnsWidth="150,150,200,250,150"
                            onRowMouseOver="this.style.backgroundColor='#eff7ff'"
                            onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
                <f:facet name="header">
                    Chamados
                </f:facet>
                <rich:column>
                    <f:facet name="header">
                        #{messages.idAtendimento}
                    </f:facet>
                    #{_atendimentos.idAtendimento}
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        #{messages.dataAberturaAtendimento}
                    </f:facet>
                    #{_atendimentos.dataAbertura}
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        #{messages.usuarioResponsavelAtendimento}
                    </f:facet>
                    #{_atendimentos.usuarioAbertura.login}
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        #{messages.localAtendimento}
                    </f:facet>
                    #{_atendimentos.equipamento.local.nome}
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        #{messages.statusAtendimento}
                    </f:facet>
                    #{_atendimentos.status}
                </rich:column>
                <rich:column>
                    <a4j:commandLink id="clDetalhar"
                                     action="#{atendimentoDetalhaAction.setup(_atendimentos)}"
                                     immediate="true"
                                     styleClass="link dr-toolbar-ext rich-toolbar">
                        <h:graphicImage value="/resources/images/details.gif"/>
                        <h:outputText value="#{messages.telaChamadoDetalhar}"/>
                    </a4j:commandLink>
                    <a4j:commandLink id="clAlterar"
                                     immediate="true"
                                     action="#{atendimentoAlterarAction.setup(_atendimentos.idAtendimento)}"
                                     styleClass="link dr-toolbar-ext rich-toolbar">
                        <h:graphicImage value="/resources/images/accessories-text-editor.png"/>
                        <h:outputText value="#{messages.telaChamadoFechar}"/>
                    </a4j:commandLink>
                    <a4j:commandLink id="clExcluir"
                                     action="#{atendimentoExcluirAction.setup(_atendimentos)}"
                                     oncomplete="Richfaces.showModalPanel('conf_delete')"
                                     reRender="dtAtendimentos"
                                     styleClass="link dr-toolbar-ext rich-toolbar">
                        <h:graphicImage value="/resources/images/delete.gif"/>
                        <h:outputText value="#{messages.telaChamadoExcluir}"/>
                    </a4j:commandLink>
                </rich:column>
            </rich:dataTable>
        </a4j:form>
        <a4j:form id="formModal">
            <rich:modalPanel id="conf_delete"  width="250" height="100">
                <f:facet name="header">
                    <h:outputText value="Confirmação de exclusão do Chamado"/>
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
                        <h:graphicImage value="/images/modal/close.png" styleClass="hidelink" id="hidelink"/>
                        <rich:componentControl for="panel" attachTo="hidelink" operation="hide" event="onclick"/>
                    </h:panelGroup>
                </f:facet>
                <center>
                    Confirma a exclusão?<br/>
                    <br/>
                    <h:commandLink id="cmdLinkConfirmar" actionListener="#{atendimentoExcluirAction.excluir(atendimentoPesquisarAction)}"
                                   styleClass="link dr-toolbar-ext rich-toolbar">
                        <h:graphicImage id="btnSim" value="/resources/images/dialog-ok-old.png" />
                        <h:outputText value="Sim"/>
                        <rich:componentControl for="conf_delete" attachTo="cmdLinkConfirmar" operation="hide" event="onclick" />
                    </h:commandLink>

                    <rich:spacer width="10"/>

                    <h:commandLink id="cmdLinkCancelar" action="#{atendimentoExcluirAction.cancelar}"
                                   styleClass="link dr-toolbar-ext rich-toolbar">
                        <h:graphicImage id="btnNao" value="/resources/images/delete.gif" style="border:0px"/>
                        <h:outputText value="Não"/>
                        <rich:componentControl for="conf_delete" attachTo="cmdLinkCancelar" operation="hide" event="onclick" />
                    </h:commandLink>
                </center>
            </rich:modalPanel>
        </a4j:form>
    </ui:define>
</ui:composition>